<template>
    <el-card v-loading="loading" shadow="never">
    <el-form :model="form" label-width="180px">
      <el-tabs v-model="activeName">
        <el-tab-pane label="PayPal設置" name="first">
            <el-form-item label="clientId" prop="units">
              <el-input v-model="form.clientId" placeholder="clientId" ></el-input>
            </el-form-item>
            <el-form-item label="clientSecret" prop="units">
              <el-input v-model="form.clientSecret" placeholder="clientSecret" ></el-input>
            </el-form-item>
            <el-form-item label="status"  >
                <el-switch v-model="form.status" active-text="live"  inactive-text="沙盒" :active-value="1" :inactive-value="2"/>
            </el-form-item>
            
        </el-tab-pane>

        <!-- <el-tab-pane label="推送" name="second">
          <el-form-item label="推送">
            <Editor v-model="form.push" />
          </el-form-item>
        </el-tab-pane> -->
      </el-tabs>
      <el-form-item>
        <el-button type="primary" @click="submit">保存</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup>
import { reactive, ref } from "vue";
import { updatepaypal, getpaypal } from "@/api/store.js";
import { msg } from "@/composables/util"

const form = reactive({
    clientId: 1,
    clientSecret: 1,
    status: 2,

});
const loading = ref(false);

const activeName = ref("first");
function getData() {
  loading.value = true;
  getpaypal()
    .then((res) => {
      for (const k in form) {
        form[k] = res[k];
      }
    })
    .finally((err) => {
      loading.value = false;
    });
}

getData();

const submit = () => {
  loading.value = true;
  updatepaypal(form)
    .then((res) => {
      msg("修改成功");
    })
    .finally(() => {
      loading.value = false;
    });
};
</script>